package com.woniuxy.yoga.admin.service.impl;

import com.woniuxy.yoga.admin.dao.mapper.AdminAccountMapper;
import com.woniuxy.yoga.admin.dao.model.AdminAccount;
import com.woniuxy.yoga.admin.dao.model.AdminRole;
import com.woniuxy.yoga.admin.dao.mapper.AdminRoleMapper;
import com.woniuxy.yoga.admin.model.exception.AdminException;
import com.woniuxy.yoga.admin.model.exception.AdminExceptionCode;
import com.woniuxy.yoga.admin.service.AdminRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 管理员角色表 服务实现类
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年11月28日
 */
@Service
public class AdminRoleServiceImpl extends ServiceImpl<AdminRoleMapper, AdminRole> implements AdminRoleService {

    @Autowired
    private AdminAccountMapper adminAccountMapper;
    @Autowired
    private AdminRoleMapper adminRoleMapper;

    /**
     * 根据账号ID查询管理员角色
     * @param accountId
     * @return
     */
    @Override
    public AdminRole selectRoleByAccountId(Integer accountId) {
        //查询管理员账号信息是否存在
        AdminAccount adminAccount = adminAccountMapper.selectById(accountId);
        if (adminAccount==null) {
            throw new AdminException(AdminExceptionCode.ADMIN_EXCEPTION_CODE_ACCOUNT_NOTEXITS);
        }
        //查询角色是否存在
        AdminRole adminRole = adminRoleMapper.selectById(adminAccount.getRoleId());
        if (adminRole==null) {
            throw new AdminException(AdminExceptionCode.ADMIN_EXCEPTION_CODE_ROLE_NOTEXISTS);
        }
        return adminRole;
    }
}
